gas = [6, 1, 4, 3, 5]
cost = [3, 8, 2, 4, 2]

if sum(gas) < sum(cost):
    print("no")
    exit(0)


def main_process(i, j):
    current = 0
    way = 0
    for k in range(i):
        if j + k >= len(gas):
            m = j + k - len(gas)
        else:
            m = j + k
        if gas[m] + current >= cost[m]:
            way = way + 1
            current = current + (gas[m] - cost[m])
        else:
            return main_process(len(gas), j + 1)

        if way == len(gas):
            return j

        if j > len(gas):
            return -1


print(main_process(len(gas), 0))
